package com.wgj.android.dialog;

import android.app.DialogFragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatDialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.jiaai.xui.utils.XDensityUtils;
import com.wgj.android.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/1/31.
 */

public class QDDialog extends AppCompatDialogFragment {
    private  boolean isOk;
    private  String money;

    @BindView(R.id.tl_qd1)
    View tl_qd1;
    @BindView(R.id.tx_qdnum)
    TextView tx_qdnum;
    @BindView(R.id.tl_eeror)
    TextView tl_eeror;
    public  static  QDDialog getInstael(boolean isOk,String money){
            QDDialog qdDialog=new QDDialog();
            Bundle bundle=new Bundle();
            bundle.putBoolean("isOk",isOk);
            bundle.putString("money",money);
            qdDialog.setArguments(bundle);
            return  qdDialog;
    }
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        money=getArguments().getString("money");
        isOk=getArguments().getBoolean("isOk");
        setStyle(DialogFragment.STYLE_NORMAL, R.style.dialog_setting);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.qd_dialog ,container,false);
        ButterKnife.bind(this,view);
        if (isOk){
            tl_qd1.setVisibility(View.VISIBLE);
            tx_qdnum.setText(money);
        }else {
            tl_qd1.setVisibility(View.GONE);
            tl_eeror.setVisibility(View.VISIBLE);
        }
        return view;
    }

    @Override
    public void onStart() {
        super.onStart();
        getDialog().setCanceledOnTouchOutside(true); // 外部点击取消
        // 设置宽度为屏宽, 靠近屏幕底部。
        Window window = getDialog().getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();

        lp.height = XDensityUtils.getScreenHeight();
        lp.width = XDensityUtils.getScreenWidth();
        window.setAttributes(lp);
    }
}
